<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SHOP 管理中心 - 商品分类 </title>
<base href="__STATIC__/Admin/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/general.css" rel="stylesheet" type="text/css" />
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<style>
	.cname:hover{
		background: #ccc;
	}
	.descr{
		width: 100px;
		display: block;/*内联对象需加*/	
		word-break:keep-all;/* 不换行 */
		white-space: nowrap;/* 不换行 */
		overflow: hidden;/* 内容超出宽度时隐藏超出部分的内容 */
		text-overflow: ellipsis;/* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/
	}
	.descr:hover{
        width: auto;/*或者width:100%;*/
	}
</style>
</head>
<body>

<h1>
<span class="action-span"><a href="{:url('Admin/Category/cate_add')}">添加分类</a></span>
<span class="action-span1"><a href="index.php?act=main">SHOP 管理中心</a> </span><span id="search_id" class="action-span1"> - 商品分类 </span>
<div style="clear:both"></div>
</h1>

<!-- start ad position list -->
	<div class="list-div" id="listDiv" style="height: 200px;">
		<table width="100%" cellspacing="1" cellpadding="2" id="list-table">
			<tbody>
				<tr>
					<th>分类名称</th>
          <th>分类描述</th>
					<th>导航栏</th>
					<th>是否显示</th>
					<th>操作</th>
				</tr>
        {foreach $list as $v}
				<tr align="center" class="0" id="0_1">
					<td align="center" class="first-cell" width="10%"><span class="cname">{$v.cat_name}</span></td>
		            <td align="center" class="first-cell" width="50%"><span class="descr">{$v.cat_desc}</span></td>
		            {if condition="($v['is_nav'] == 0)"}
			            <td align="center" width="10%"><img src="images/no.gif" class="is_nav" id="{$v.cat_id}" title="点击修改"></td>
			          {elseif condition="($v['is_nav'] == 1)"/}
			            <td align="center" width="10%"><img src="images/yes.gif" class="is_nav" id="{$v.cat_id}" title="点击修改"></td>
			        {/if}
			        {if condition="($v['is_show'] == 0)"}
			            <td align="center" width="10%"><img src="images/no.gif" class="is_show" id="{$v.cat_id}" title="点击修改"></td>
			        {elseif condition="($v['is_show'] == 1)"/}
			            <td align="center" width="10%"><img src="images/yes.gif" class="is_show" id="{$v.cat_id}" title="点击修改"></td>
			        {/if}
					<td width="20%" align="center">
						<a href="javascript:;" class="save" id="{$v.cat_id}">编辑</a> |
						<a href="javascript:;" class="delete" id="{$v.cat_id}">移除</a>
					</td>
				</tr>
	     {/foreach}  
	</tbody>
  </table>
</div>
 <div>{$list->render()}</div>

<div id="footer">
	<div>版权所有 &copy; 2006-2013 软工教育 - 高级PHP - </div>
</div>

</body>
<script src="jquery.js"></script>
<script>
		$(".is_nav").click('click',function(){
			 var src = $(this).attr('src');
		       if(src=='images/yes.gif'){
			        $(this).attr('src','images/no.gif');
			        var is_nav=0;
		       }else{
			        $(this).attr('src','images/yes.gif');
			        var is_nav=1;
		       }
		       var id=$(this).attr('id');
		       $.ajax({
		         url: "{:url('Admin/Category/cate_update')}",
		         type: 'get',
		         dataType: 'json',
		         data: {id:id,is_nav:is_nav},
		         success:function(e){
		        	if (e===false) {
				        history.go(0);
				    }
		         }
		       })
		});

		$(".is_show").click('click',function(){
			 var src = $(this).attr('src');
		       if (src=='images/yes.gif') {
			        $(this).attr('src','images/no.gif');
			        var is_show=0;
		       }else{
			        $(this).attr('src','images/yes.gif');
			        var is_show=1;
		       }
		       var id=$(this).attr('id');
		       $.ajax({
		         url: "{:url('Admin/Category/cate_upshow')}",
		         type: 'get',
		         dataType: 'json',
		         data: {id:id,is_show:is_show},
		         success:function(e){
		      		if (e===false) {
				        history.go(0);
				    }
		         }
		       })
		});


		$(".save").on('click',function(){
			var td=$(this).parent();
     		var tr=$(this).parents('tr');
			var id = $(this).attr('id');
			var text = $(this).text();
			if(text == '编辑'){
				$(this).text('确定修改');
				tr.children().eq(0).html('<input type="text" value="'+tr.children().eq(0).text()+'" id="name'+id+'">');
				tr.children().eq(1).html('<input type="text" value="'+tr.children().eq(1).text()+'" id="descr'+id+'">');
			}else{
				$(this).text('编辑');
				var name=$('#name'+id).val();
				var descr=$('#descr'+id).val();
				tr.children().eq(0).html(name);
				tr.children().eq(1).html(descr);
				$.ajax({
					url:"{:url('Admin/Category/cate_save')}",
					type:'get',
					data:{id:id,cat_name:name,cat_desc:descr},
					dataType:'json',
					success:function(e){
						if (e===false) {
				           history.go(0);
				        }
					}
				});
			}
		});

		$(".delete").on('click',function(){
			var id = $(this).attr('id');
				$.ajax({
	              url:"{:url('Admin/Category/cate_del')}",
	              type:"get",
	              data:{id:id},
	              dataType:'json',
	              success:function(e){
	              	// console.log(e)
	                if(e.code==1){
	                    alert(e.msg);
	                    history.go(0)
	                }else if(e.code==0){
	                    alert(e.msg);
	                    history.go(0)
	                }
	              }
	          });
		});

		
</script>
</html>